#ifndef _MYI2C_H
#define _MYI2C_H   1

#include <inttypes.h>
#include <compat/twi.h>

#define I2C_READ    1
#define I2C_WRITE   0

//  initialize the I2C master interace. Need to be called only once
void i2c_init();

//  Terminates the data transfer and releases the I2C bus
void i2c_stop();

// Issues a start condition and sends address and transfer direction
unsigned char i2c_start(unsigned char addr);

// Issues a repeated start condition and sends address and transfer direction
//unsigned char i2c_rep_start(unsigned char addr);

// Issues a start condition and sends address and transfer direction
//void i2c_start_wait(unsigned char addr);

// Send one byte to I2C device
// data  byte to be transfered
// 0 write successful
// 1 write failed
unsigned char i2c_write(unsigned char data);

// read one byte from the I2C device, request more data from device
unsigned char i2c_readAck();

// read one byte from the I2C device, read is followed by a stop condition
unsigned char i2c_readNak();

//void i2cWrite(uint8_t addr, uint8_t reg, uint8_t val);
//uint8_t i2cRead(uint8_t addr, uint8_t reg);
//uint8_t i2cDeviceReady(uint8_t addr);

#endif
